package com.ucode.model.hrm.form;

import com.ucode.model.hrm.enums.HrmLeaveApplyTypeEnum;
import com.ucode.tool.validator.InEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;

@Schema(description = "人力资源系统 - 请假申请Form")
@Data
@EqualsAndHashCode
public class HrmLeaveApplyRecordForm {
    /**
     * 员工ID
     */
    @Schema(description = "员工ID", requiredMode = Schema.RequiredMode.AUTO)
    private Long employeeId;

    /**
     * 请假类型：1-年假 2-病假 3-事假 4-调休
     */
    @Schema(description = "请假类型 参考枚举 HrmLeaveApplyTypeEnum", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    @NotNull(message = "请假类型不能为空")
    @InEnum(value = HrmLeaveApplyTypeEnum.class)
    private Integer leaveType;
    /**
     * 请假开始时间
     */
    @Schema(description = "请假开始时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "请假开始时间不能为空")
    private LocalDateTime startTime;
    /**
     * 请假结束时间
     */
    @Schema(description = "请假结束时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "请假结束时间不能为空")
    private LocalDateTime endTime;
    /**
     * 请假原因
     */
    @Schema(description = "请假原因", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "请假原因不能为空")
    @Size(max = 256, message = "请假原因不能超过 256 个字符")
    private String reason;


    @AssertTrue(message = "结束时间必须要大于开始时间")
    public boolean isTimeIntervalCheck() {
        if(this.endTime.isAfter(this.startTime)){
            return true;
        }
        return false;
    }
}
